/*
 * AñadirVaca.java
 *
 * Created on 13-dic-2011, 20:55:03
 */

package interfazgrafica.modificar.vacas;

import interfazgrafica.ayuda.VentanaAyuda;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Lauaa
 */
public class AñadirVaca extends javax.swing.JDialog {
    private final Connection conn;
    private final Statement stmt;
    private static String[] args;

    /** Creates new form AñadirVaca */
    public AñadirVaca(java.awt.Frame parent, boolean modal) throws ClassNotFoundException, SQLException {
        super(parent, modal);
        initComponents();
        //Accedo a la base de datos.
            Class.forName("oracle.jdbc.OracleDriver");
            conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "system", "terrano89");
            stmt = conn.createStatement();


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelId = new javax.swing.JLabel();
        jLabelPadre = new javax.swing.JLabel();
        jLabelMadre = new javax.swing.JLabel();
        jLabelPPadre = new javax.swing.JLabel();
        jLabelPMadre = new javax.swing.JLabel();
        jLabelMPadre = new javax.swing.JLabel();
        jLabelMMadre = new javax.swing.JLabel();
        jLabelNumero = new javax.swing.JLabel();
        jLabelFechaNacimiento = new javax.swing.JLabel();
        jLabelCalificacion = new javax.swing.JLabel();
        jLabelRecalificacion = new javax.swing.JLabel();
        jTextFieldId = new javax.swing.JTextField();
        jTextFieldPadre = new javax.swing.JTextField();
        jTextFieldMadre = new javax.swing.JTextField();
        jTextFieldPPadre = new javax.swing.JTextField();
        jTextFieldPMadre = new javax.swing.JTextField();
        jTextFieldMPadre = new javax.swing.JTextField();
        jTextFieldMMadre = new javax.swing.JTextField();
        jTextFieldNumero = new javax.swing.JTextField();
        jTextFieldCalificacion = new javax.swing.JTextField();
        jTextFieldRecalificacion = new javax.swing.JTextField();
        jButtonGuardar = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();
        jButtonAyuda = new javax.swing.JButton();
        jTextFieldFechaNacimiento = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(cowmanager.CowManagerApp.class).getContext().getResourceMap(AñadirVaca.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jLabelId.setText(resourceMap.getString("jLabelId.text")); // NOI18N
        jLabelId.setName("jLabelId"); // NOI18N

        jLabelPadre.setText(resourceMap.getString("jLabelPadre.text")); // NOI18N
        jLabelPadre.setName("jLabelPadre"); // NOI18N

        jLabelMadre.setText(resourceMap.getString("jLabelMadre.text")); // NOI18N
        jLabelMadre.setName("jLabelMadre"); // NOI18N

        jLabelPPadre.setText(resourceMap.getString("jLabelPPadre.text")); // NOI18N
        jLabelPPadre.setName("jLabelPPadre"); // NOI18N

        jLabelPMadre.setText(resourceMap.getString("jLabelPMadre.text")); // NOI18N
        jLabelPMadre.setName("jLabelPMadre"); // NOI18N

        jLabelMPadre.setText(resourceMap.getString("jLabelMPadre.text")); // NOI18N
        jLabelMPadre.setName("jLabelMPadre"); // NOI18N

        jLabelMMadre.setText(resourceMap.getString("jLabelMMadre.text")); // NOI18N
        jLabelMMadre.setName("jLabelMMadre"); // NOI18N

        jLabelNumero.setText(resourceMap.getString("jLabelNumero.text")); // NOI18N
        jLabelNumero.setName("jLabelNumero"); // NOI18N

        jLabelFechaNacimiento.setText(resourceMap.getString("jLabelFechaNacimiento.text")); // NOI18N
        jLabelFechaNacimiento.setName("jLabelFechaNacimiento"); // NOI18N

        jLabelCalificacion.setText(resourceMap.getString("jLabelCalificacion.text")); // NOI18N
        jLabelCalificacion.setName("jLabelCalificacion"); // NOI18N

        jLabelRecalificacion.setText(resourceMap.getString("jLabelRecalificacion.text")); // NOI18N
        jLabelRecalificacion.setName("jLabelRecalificacion"); // NOI18N

        jTextFieldId.setText(resourceMap.getString("jTextFieldId.text")); // NOI18N
        jTextFieldId.setName("jTextFieldId"); // NOI18N
        jTextFieldId.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldIdActionPerformed(evt);
            }
        });

        jTextFieldPadre.setText(resourceMap.getString("jTextFieldPadre.text")); // NOI18N
        jTextFieldPadre.setName("jTextFieldPadre"); // NOI18N

        jTextFieldMadre.setText(resourceMap.getString("jTextFieldMadre.text")); // NOI18N
        jTextFieldMadre.setName("jTextFieldMadre"); // NOI18N

        jTextFieldPPadre.setText(resourceMap.getString("jTextFieldPPadre.text")); // NOI18N
        jTextFieldPPadre.setName("jTextFieldPPadre"); // NOI18N

        jTextFieldPMadre.setText(resourceMap.getString("jTextFieldPMadre.text")); // NOI18N
        jTextFieldPMadre.setName("jTextFieldPMadre"); // NOI18N

        jTextFieldMPadre.setText(resourceMap.getString("jTextFieldMPadre.text")); // NOI18N
        jTextFieldMPadre.setName("jTextFieldMPadre"); // NOI18N

        jTextFieldMMadre.setText(resourceMap.getString("jTextFieldMMadre.text")); // NOI18N
        jTextFieldMMadre.setName("jTextFieldMMadre"); // NOI18N

        jTextFieldNumero.setText(resourceMap.getString("jTextFieldNumero.text")); // NOI18N
        jTextFieldNumero.setName("jTextFieldNumero"); // NOI18N

        jTextFieldCalificacion.setText(resourceMap.getString("jTextFieldCalificacion.text")); // NOI18N
        jTextFieldCalificacion.setName("jTextFieldCalificacion"); // NOI18N

        jTextFieldRecalificacion.setText(resourceMap.getString("jTextFieldRecalificacion.text")); // NOI18N
        jTextFieldRecalificacion.setName("jTextFieldRecalificacion"); // NOI18N

        jButtonGuardar.setText(resourceMap.getString("jButtonGuardar.text")); // NOI18N
        jButtonGuardar.setName("jButtonGuardar"); // NOI18N
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        jButtonCancelar.setText(resourceMap.getString("jButtonCancelar.text")); // NOI18N
        jButtonCancelar.setName("jButtonCancelar"); // NOI18N
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        jButtonAyuda.setText(resourceMap.getString("jButtonAyuda.text")); // NOI18N
        jButtonAyuda.setName("jButtonAyuda"); // NOI18N
        jButtonAyuda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAyudaActionPerformed(evt);
            }
        });

        jTextFieldFechaNacimiento.setText(resourceMap.getString("jTextFieldFechaNacimiento.text")); // NOI18N
        jTextFieldFechaNacimiento.setName("jTextFieldFechaNacimiento"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(606, Short.MAX_VALUE)
                .addComponent(jButtonAyuda)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelRecalificacion)
                        .addGap(18, 18, 18)
                        .addComponent(jTextFieldRecalificacion, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(353, 353, 353))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabelCalificacion)
                            .addGap(18, 18, 18)
                            .addComponent(jTextFieldCalificacion, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                            .addGap(353, 353, 353))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabelNumero)
                                    .addGap(18, 18, 18)
                                    .addComponent(jTextFieldNumero, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabelMadre)
                                    .addGap(18, 18, 18)
                                    .addComponent(jTextFieldMadre, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabelPadre)
                                    .addGap(18, 18, 18)
                                    .addComponent(jTextFieldPadre, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabelId)
                                    .addGap(18, 18, 18)
                                    .addComponent(jTextFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabelFechaNacimiento)
                                    .addGap(18, 18, 18)
                                    .addComponent(jTextFieldFechaNacimiento, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)))
                            .addGap(18, 18, 18)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabelPPadre)
                                        .addComponent(jLabelPMadre)
                                        .addGroup(layout.createSequentialGroup()
                                            .addGap(2, 2, 2)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabelMMadre)
                                                .addComponent(jLabelMPadre))))
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextFieldMMadre, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                                        .addComponent(jTextFieldPPadre, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jTextFieldPMadre, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                                        .addComponent(jTextFieldMPadre, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                                        .addComponent(jButtonCancelar, javax.swing.GroupLayout.Alignment.TRAILING))
                                    .addGap(98, 98, 98))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addContainerGap()))))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(395, Short.MAX_VALUE)
                .addComponent(jButtonGuardar)
                .addGap(213, 213, 213))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelId)
                    .addComponent(jTextFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelPadre)
                    .addComponent(jTextFieldPadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelPPadre)
                    .addComponent(jTextFieldPPadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelPMadre)
                    .addComponent(jTextFieldPMadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(98, 98, 98)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelNumero)
                            .addComponent(jTextFieldNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelFechaNacimiento)
                            .addComponent(jTextFieldFechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelCalificacion)
                            .addComponent(jTextFieldCalificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelRecalificacion)
                            .addComponent(jTextFieldRecalificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelMadre)
                            .addComponent(jTextFieldMadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelMPadre)
                            .addComponent(jTextFieldMPadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelMMadre)
                            .addComponent(jTextFieldMMadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(55, 55, 55)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonGuardar)
                    .addComponent(jButtonCancelar))
                .addGap(65, 65, 65))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(493, Short.MAX_VALUE)
                .addComponent(jButtonAyuda)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldIdActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldIdActionPerformed

    private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed

        String consulta = "INSERT INTO vacas VALUES (";
        consulta = consulta + "'" + jTextFieldPadre.getText() +"', ";
        consulta = consulta + "'" +jTextFieldMadre.getText() +"', ";
        consulta = consulta + "'" +jTextFieldPPadre.getText() +"', ";
        consulta = consulta + "'" +jTextFieldPMadre.getText() +"', ";
        consulta = consulta + "'" +jTextFieldMMadre.getText() +"', ";
        consulta = consulta + "'" +jTextFieldMPadre.getText() +"', ";
        consulta = consulta + jTextFieldNumero.getText() +", ";
        consulta = consulta + "'" +jTextFieldFechaNacimiento.getText() +"', ";
        consulta = consulta + "'" +jTextFieldCalificacion.getText() +"', ";
        consulta = consulta + "'" +jTextFieldRecalificacion.getText() + "', ";
        consulta = consulta + "'" +jTextFieldId.getText() +"')";

                //Hago una consulta y la guardo en rs.
	ResultSet rs = null;
        try {
            rs = stmt.executeQuery(consulta);
        } catch (SQLException ex) {
            Logger.getLogger(AñadirVaca.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            rs.close();
        } catch (SQLException ex) {
            Logger.getLogger(AñadirVaca.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            stmt.close();
        } catch (SQLException ex) {
            Logger.getLogger(AñadirVaca.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(AñadirVaca.class.getName()).log(Level.SEVERE, null, ex);
        }
        ModificarVacas.main(args);
        this.dispose();
    }//GEN-LAST:event_jButtonGuardarActionPerformed

    private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
        this.dispose();
        ModificarVacas.main(args);
    }//GEN-LAST:event_jButtonCancelarActionPerformed

    private void jButtonAyudaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAyudaActionPerformed
        VentanaAyuda ayuda = new VentanaAyuda("Modificar vacas");
        ayuda.setVisible(true);
    }//GEN-LAST:event_jButtonAyudaActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(final String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    AñadirVaca dialog = new AñadirVaca(new javax.swing.JFrame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                        public void windowClosing(java.awt.event.WindowEvent e) {
                            ModificarVacas.main(args);
                        }
                    });
                    dialog.setVisible(true);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(AñadirVaca.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(AñadirVaca.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAyuda;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelCalificacion;
    private javax.swing.JLabel jLabelFechaNacimiento;
    private javax.swing.JLabel jLabelId;
    private javax.swing.JLabel jLabelMMadre;
    private javax.swing.JLabel jLabelMPadre;
    private javax.swing.JLabel jLabelMadre;
    private javax.swing.JLabel jLabelNumero;
    private javax.swing.JLabel jLabelPMadre;
    private javax.swing.JLabel jLabelPPadre;
    private javax.swing.JLabel jLabelPadre;
    private javax.swing.JLabel jLabelRecalificacion;
    private javax.swing.JTextField jTextFieldCalificacion;
    private javax.swing.JTextField jTextFieldFechaNacimiento;
    private javax.swing.JTextField jTextFieldId;
    private javax.swing.JTextField jTextFieldMMadre;
    private javax.swing.JTextField jTextFieldMPadre;
    private javax.swing.JTextField jTextFieldMadre;
    private javax.swing.JTextField jTextFieldNumero;
    private javax.swing.JTextField jTextFieldPMadre;
    private javax.swing.JTextField jTextFieldPPadre;
    private javax.swing.JTextField jTextFieldPadre;
    private javax.swing.JTextField jTextFieldRecalificacion;
    // End of variables declaration//GEN-END:variables

}
